package com.huluobo.a2201mvvm_imdemo.splash;

import android.content.Intent;
import android.os.Handler;

import com.huluobo.a2201mvvm_imdemo.MainActivity;
import com.huluobo.a2201mvvm_imdemo.R;
import com.huluobo.a2201mvvm_imdemo.databinding.ActivitySplashBinding;
import com.huluobo.a2201mvvm_imdemo.demo.MyView;
import com.huluobo.a2201mvvm_imdemo.login.LoginActivity;
import com.huluobo.a2201mvvm_imdemo.mvvm.BaseActivity;
import com.hyphenate.chat.EMClient;

public class SplashActivity extends BaseActivity<ActivitySplashBinding> {

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
//        new Handler().postDelayed(() -> {
//            if (isLoggedIn()) {
//                //之前登录过,跳转到主页面
//                Intent intent = new Intent(this, MainActivity.class);
//                startActivity(intent);
//            } else {
//                //之前没登陆过,跳转到登录页面
//                Intent intent = new Intent(this, LoginActivity.class);
//                startActivity(intent);
//            }
//        }, 2000);
        dataBinding.splashMyView.start(1);
        dataBinding.splashMyView.setOnAniEndListener(() -> {
            if (isLoggedIn()) {
                //之前登录过,跳转到主页面
                Intent intent = new Intent(this, MainActivity.class);
                startActivity(intent);
                finish();
            } else {
                //之前没登陆过,跳转到登录页面
                Intent intent = new Intent(this, LoginActivity.class);
                startActivity(intent);
                finish();
            }
        });
    }

    private boolean isLoggedIn() {
        return EMClient.getInstance().isLoggedIn();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_splash;
    }
}